﻿using SharPy.GameClasses;
using SharPy.Parser;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;

namespace SharPy.GameSettings
{
    /// <summary>
    /// Class to parse config file and get some settings from it
    /// </summary>
    static class clConfig
    {
        static StorageFile optionsFile;
        static List<clTextLine> optionsText;

        static internal async Task<StorageFile> getOptionsFile()
        {
            string pathToGameFolder = clSettings.getFolder().Result.Path;
            optionsFile = await StorageFile.GetFileFromPathAsync(pathToGameFolder + "\\options.rpy");
            optionsText = await clText.getText(optionsFile); 
            return null;
        }

        internal static async Task<Windows.UI.Xaml.Media.Imaging.BitmapImage> getLastGameImage()
        {
            clTextLine line = optionsText.Find(l => l.sLine.Contains("mm_root"));
            string name = System.Text.RegularExpressions.Regex.Match(line.sLine, @"""(.*)""").Value;

            return await clImages.getImageByPath(name);
        }

        static clConfig()
        {
            getOptionsFile();
        }
    }
}
